package com.heima.wemedia.controller.v1;

import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.dtos.WmMaterialDto;
import com.heima.wemedia.service.WmMaterialService;
import io.swagger.models.auth.In;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/api/v1/material")
@Slf4j
public class WmMaterialController {

    @Autowired
    private WmMaterialService wmMaterialService;

    /**
     * 查询素材列表
     *
     * @param wmMaterialDto
     * @return
     */
    @PostMapping("list")
    public ResponseResult list(@RequestBody WmMaterialDto wmMaterialDto){
        log.info("查询自媒体素材列表：{}",wmMaterialDto);
        return wmMaterialService.pageQuery(wmMaterialDto);
    }

    /**
     * 素材上传
     *
     * @param multipartFile
     * @return
     */
    @PostMapping("/upload_picture")
    public ResponseResult upload(MultipartFile multipartFile){
        log.info("素材上传：{}",multipartFile.getOriginalFilename());
        return wmMaterialService.upload(multipartFile);
    }

    /**
     * 收藏素材
     *
     * @param id
     * @return
     */
    @GetMapping("/collect/{id}")
    public ResponseResult collect(@PathVariable("id") Integer id){
        log.info("收藏素材：{}",id);
        wmMaterialService.collect(id);
        return ResponseResult.okResult("SUCCESS");
    }

    /**
     * 删除图片素材
     *
     * @param id
     * @return
     */
    @GetMapping("/del_picture/{id}")
    public ResponseResult delete(@PathVariable("id") Integer id){
        log.info("删除图片素材：{}",id);
        wmMaterialService.delete(id);
        return ResponseResult.okResult("SUCCESS");
    }

    /**
     * 取消收藏图片素材
     *
     * @param id
     * @return
     */
    @GetMapping("/cancel_collect/{id}")
    public ResponseResult cancelCollect(@PathVariable("id") Integer id){
        log.info("取消收藏图片素材：{}",id);
        wmMaterialService.cancelCollect(id);
        return ResponseResult.okResult("SUCCESS");
    }
}
